#include<iostream>
#include "EquationSolver.h"
#include <cmath>  
using namespace std;

class Func :public Function{
    private:
        double A, B, C, E;
    public:
        Func(){}
        Func(double l,double h, double D,double b){
            A = l*sin(b/180*M_PI);
            B = l*cos(b/180*M_PI);
            C = (h+0.5*D)*sin(b/180*M_PI) - 0.5*D*tan(b/180*M_PI);
            E = (h+0.5*D)*cos(b/180*M_PI)-0.5*D;
        }
        double operator () (const double &x) {
            return A*sin(x)*cos(x) + B*sin(x)*sin(x) - C*cos(x) - E*sin(x);
        }
        double diff(const double &x) {
            return A*(-sin(x)*sin(x)+cos(x)*cos(x)) + 2*B*cos(x)*sin(x)+ C*sin(x) - E*cos(x);
        }
};

int main(){
    // F.1
    Func func1(89, 49, 55, 11.5);
    cout << "F.1" << endl;
    NewtonSolver sol1(func1,33.0/180.0*M_PI, 100);
    double ans1 = sol1.solve();
    cerr << "alpha = " << ans1/M_PI*180 << " degree" << endl;

    // F.2
    Func func2(89, 49, 30, 11.5);
    cout << "F.2" << endl;
    NewtonSolver sol2(func2,33.0/180.0*M_PI, 100);
    double ans2 = sol2.solve();
    cerr << "alpha = " << ans2/M_PI*180 << " degree" << endl;

    // F.3
    Func func3(89, 49, 55, 11.5);
    cout << "F.3" << endl;
    SecantSolver sol3(func3, 30/180.0*M_PI, 60.0/180.0*M_PI, eps, 100);
    double ans3 = sol3.solve();
    cerr << "alpha = " << ans3/M_PI*180 << " degree" << endl;
    SecantSolver sol4(func3, 60/180.0*M_PI, 90.0/180.0*M_PI, eps, 100);
    double ans4= sol4.solve();
    cerr << "alpha = " << ans4/M_PI*180 << " degree" << endl;
    SecantSolver sol5(func3, 90/180.0*M_PI, 150.0/180.0*M_PI, eps, 100);
    double ans5= sol5.solve();
    cerr << "alpha = " << ans5/M_PI*180 << " degree" << endl;
    
}

